package com.hc.music.controller;

import com.hc.music.common.R;
import com.hc.music.entity.Singer;
import com.hc.music.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("singer")
public class SingerController {
    @Autowired
    SingerService singerService;

    @RequestMapping(value = "insert",method = RequestMethod.POST)
    public R addSinger(@RequestBody Singer singer){
        return singerService.addSinger(singer);
    }

    @RequestMapping("delete")
    public R deleteSinger(@RequestParam Integer id){
        return singerService.deleteSinger(id);
    }

    @RequestMapping("selectAllSinger")
    public R allSinger() {
        return singerService.allSinger();
    }

    // 根据歌手名查找歌手
    @RequestMapping("selectSingerByName")
    public R singerOfName(@RequestParam String name) {
        return singerService.singerOfName(name);
    }

    // 根据歌手性别查找歌手
    @RequestMapping("selectSingerBySex")
    public R singerOfSex(@RequestParam int sex) {
        return singerService.singerOfSex(sex);
    }

    // 更新歌手信息
    @RequestMapping("updateSingerInfo")
    public R updateSingerMsg(@RequestBody Singer singer) {
        return singerService.updateSingerMsg(singer);
    }

    // 更新歌手头像
    @RequestMapping(value = "updateSingerAvator",method = RequestMethod.POST)
    public R updateSingerPic(@RequestParam("file") MultipartFile avatorFile, @RequestParam("id") int id) {
        return singerService.updateSingerPic(avatorFile, id);
    }
}
